package com.enzoism.springboot.dive.controller;

import com.enzoism.springboot.dive.result.RequestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("redis")
public class RedisController {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @GetMapping("set")
    public RequestResult testRedis(@RequestParam String key, @RequestParam String value) {
        stringRedisTemplate.opsForValue().append(key, value);
        return RequestResult.success("Redis数据存放成功");
    }

    @GetMapping("get")
    public RequestResult getRedis(@RequestParam String key) {
        String value = stringRedisTemplate.opsForValue().get(key);
        return RequestResult.success("Redis数据取出成功：" + value);
    }

}
